<?php
	require("./include/common.php");
	require("./include/nav.class.php");
	$a=new nav();
	$a->table="bar";
	$a->where=1;
	switch($action){
		case "add":
			if($dosubmit){
				if(!$info["text"]||!$info["link"])	msg("请把资料填写完善!");
				$info=new_htmlspecialchars($info);
				$a->add($info);
				msg($msg["add"],"?");
			}
			break;
		case "edit": 
			$id=intval($id);if(!$id)	msg($msg["id"]);
			if($dosubmit){
				if(!$info["text"]||!$info["link"])	msg("请把资料填写完善!");
				$info=new_htmlspecialchars($info);
				$a->update($info," id=$id ");
				msg($msg["edit"],"?");				
			}else{
				$r=$a->get_one($id);
			}
			break;
		case "display":
			$id=intval($id);if(!$id)	msg($msg["id"]);
			switch($display){
				case "hide":
					$a->hide($id);
					break;
				case "show":
					$a->show($id);
					break;
			}
			redirect("?");
			break;
		default:
			$q=$a->get_all();
			break;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Navigation settings</title>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
	color: #000000;
}
body {
	background-color: #FFFFFF;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style></head>

<body>
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td>&nbsp; 分类小导航 ：<a href="?action=add">添加导航栏</a>	<a href="?">导航栏管理</a></td>
  </tr>
</table>
<?php if($action=='add'){ ?>
<form action="" method="post" id="myfrm">
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td align="right" bgcolor="#f1f1f1">文字：</td>
    <td align="left"><input name="info[text]" type="text" id="text" size="30" maxlength="50" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">链接地址：</td>
    <td align="left"><input name="info[link]" type="text" id="link" size="30" maxlength="255" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">新页面打开：</td>
    <td align="left"><p>
      <label>
        <input type="radio" name="info[target]" value="_blank" />
        是</label>
      <label>
        <input name="info[target]" type="radio" value="_self" checked="checked" />
        否</label>
    </p></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">是否显示：</td>
    <td align="left"><p>
      <label>
        <input name="info[display]" type="radio" value="1" checked="checked" />
        是</label>
      <label>
        <input type="radio" name="info[display]" value="0" />
        否</label>
    </p></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">排序：</td>
    <td align="left"><input name="info[orders]" type="text" id="orders" size="5" maxlength="5" value="99" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">&nbsp;</td>
    <td align="left"><input type="submit" name="dosubmit" value="提交" />
      <input type="submit" name="back" value="返回" onclick="window.history.back()" /></td>
  </tr>
</table>
</form>
<?php }elseif($action=='edit'){ ?>
<form action="" method="post" id="myfrm">
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td align="right" bgcolor="#f1f1f1">文字：</td>
    <td align="left"><input name="info[text]" type="text" id="text" value="<?php echo $r["text"]; ?>" size="30" maxlength="50" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">链接地址：</td>
    <td align="left"><input name="info[link]" type="text" id="link" value="<?php echo $r["link"]; ?>" size="30" maxlength="255" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">新页面打开：</td>
    <td align="left"><p>
      <label>
        <input type="radio" name="info[target]" value="_blank" <?php if($r["target"]=="_blank") echo'checked="checked"'; ?> />
        是</label>
      <label>
        <input name="info[target]" type="radio" value="_self" <?php if($r["target"]=="_self") echo'checked="checked"'; ?> />
        否</label>
    </p></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">是否显示：</td>
    <td align="left"><p>
      <label>
        <input name="info[display]" type="radio" value="1" <?php if($r["display"]) echo'checked="checked"'; ?> />
        是</label>
      <label>
        <input type="radio" name="info[display]" value="0" <?php if(!$r["display"]) echo'checked="checked"'; ?> />
        否</label>
    </p></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">排序：</td>
    <td align="left"><input name="info[orders]" type="text" id="orders" value="<?php echo $r["orders"]; ?>" size="5" maxlength="5" /></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#f1f1f1">&nbsp;</td>
    <td align="left"><input type="submit" name="dosubmit" value="提交" />
      <input type="submit" name="back" value="返回" onclick="window.history.back()" /></td>
  </tr>
</table>
</form>
<?php }else{ ?>
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td align="center" bgcolor="#f1f1f1">文字/链接</td>
    <td align="center" bgcolor="#f1f1f1">打开方式</td>
    <td align="center" bgcolor="#f1f1f1">排序</td>
    <td align="center" bgcolor="#f1f1f1">是否显示</td>
    <td align="center" bgcolor="#f1f1f1">操作</td>
  </tr>
  <?php foreach($q as $r){ ?>
  <tr>
    <td align="center"><a title="链接地址：<?php echo $r["link"]; ?>  双击打开" ondblclick="window.open('<?php echo $r["link"]; ?>')">
	<?php echo $r["text"]; ?></a></td>
    <td align="center"><?php echo $r["target"]; ?></td>
    <td align="center"><?php echo $r["orders"]; ?></td>
    <td align="center"><?php echo $r["display"]; ?></td>
    <td align="center"><a href="?action=edit&id=<?php echo $r["id"]; ?>">编辑</a> |
	<?php if($r["display"]){ ?>
	<a href="?action=display&display=hide&id=<?php echo $r["id"]; ?>">隐藏</a>
	<?php }else{ ?>
	<a href="?action=display&display=show&id=<?php echo $r["id"]; ?>">显示</a>
	<?php } ?>
	</td>
  </tr>
  <?php } ?>
</table>
<?php } ?>
</body>
</html>
